package com.cennavi.buss.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.cennavi.buss.service.imp.ITokenService;
import com.cennavi.minemap.bean.MessageBean;

@RestController
@RequestMapping("/service/token")
public class TokenController {

	@Autowired
	private ITokenService iTokenService;

	@RequestMapping(method = RequestMethod.GET, value = "/limit")
	public @ResponseBody Integer getLimit() {
		return iTokenService.getLimit();
	}

	@RequestMapping(method = RequestMethod.POST, value = "/apply", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean apply(@RequestBody String json) {
		return iTokenService.apply(json);
	}

	@RequestMapping(method = RequestMethod.POST, value = "/update", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean update(@RequestBody String json) {
		return iTokenService.update(json);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/list/{userId}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryByUserId(@PathVariable int userId) {
		return iTokenService.queryByUserId(userId);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/listOfNoSolu/{userId}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryByUserIdOfNoSolu(@PathVariable int userId) {
		return iTokenService.queryByUserIdOfNoSolu(userId);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/{id}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean detail(@PathVariable String id) {
		return iTokenService.detail(id);
	}

	@RequestMapping(method = RequestMethod.POST, value = "/solu", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean insertTokenSolu(@RequestBody String json) {
		return iTokenService.insertTokenSolu(json);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/list/solu/{option}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryBySoluUserId(@PathVariable String option, @RequestParam("soluId") int soluId,
			@RequestParam("userId") int userId) {
		return iTokenService.queryBySoluUserId(option, soluId, userId);
	}
}
